home *** CD-ROM | disk | FTP | other *** search
- /**********************************************************************
- *
- * Copyright Apple Computer, Inc. 1986, 1992, 1995
- * All Rights Reserved
- *
- * Description: This program reads code segment 1 from a specified
- * resource file and and writes it as a data file
- * to an output file. Run this tool after patching
- * the CRC value with the CRCPatch tool.
- *
- * Calling syntax: Data rsrcFileName DataFileName
- *
- * Written: July 30, 1986.
- *
- * Modified: 09/16/92.
- * • Changed this header to be more readable.
- * • Fixed compiler warnings, by:
- * - deleting unused variable definitions
- * - adding #include <FCntl.h>.
- * • Fixed bug that caused possible bus error in
- * 32 bit mode when skipping over first 4 bytes of
- * the resource header
- *
- **********************************************************************/
-
-
- #include <stdio.h>
- #include <FCntl.h>
- #include <types.h>
- #include <osutils.h>
- #include <files.h>
- #include <resources.h>
- #include <memory.h>
- #include <errno.h>
-
-
-
- pascal void _CalcCRC (SizeCode,CodePtr,crc)
- long SizeCode;
- Ptr CodePtr;
- extern;
-
- /******************************************************************
- Main
- *******************************************************************/
- main(argc,argv)
-
- int argc;
- char *argv[];
-
- {
- short refnum;
- Handle CodeHandle; /* Handle to code resource */
- short IOR; /* IO Result */
- long SizeCode; /* Size of the code */
- Ptr CodePtr; /* Pointer to the code */
- int FileDescript; /* The file descriptor of the data file */
- unsigned NumBWritten; /* Number of bytes written per write */
- unsigned Total; /* Total number of bytes written */
-
- if (argc == 1)
- {
- fprintf(stderr,"### ERROR : No files specified.\n");
- fprintf(stderr,"### SYNTAX: Data rsrcFileName DataFileName\n");
- fprintf(stderr,"### DSCRPT: Copy code segment 1 to a data file.\n");
- }
- else if (argc != 3)
- {
- fprintf(stderr,"### ERROR : Wrong number of parameters specified.\n");
- fprintf(stderr,"### SYNTAX: Data rsrcFileName DataFileName\n");
- fprintf(stderr,"### DSCRPT: Copy code segment 1 to a data file.\n");
- }
- else
- {
- refnum = openresfile(argv[1]);
- if (refnum < 0 )
- fprintf(stderr,"### ERROR : Resource file: %s can't be opened. err = %d.\n",argv[1],refnum);
- else
- {
- CodeHandle = GetResource('CODE',1);
- HLock(CodeHandle);
- IOR = ResError();
- if (IOR != 0)
- fprintf(stderr,"### ERROR : Code resource not available. Err = %d\n",errno);
- else
- {
- SizeCode = GetHandleSize(CodeHandle);
- SizeCode = SizeCode - 4; /* Skip first 4 bytes (Resource header) */
- CodePtr = ((Ptr)*CodeHandle) + 4; /* Skip first 4 bytes (Resource header) */
-
- FileDescript = creat(argv[2]);
- if (FileDescript < 0)
- fprintf(stderr,"### ERROR : Data file: %s can't be opened. err = %d.\n",argv[2],errno);
- else
- {
- Total = 0;
- while (Total < SizeCode)
- {
- NumBWritten = write(FileDescript,CodePtr,SizeCode);
- if (NumBWritten < 0)
- {
- fprintf(stderr,"### ERROR : Write err = %d.\n",errno);
- Total = SizeCode;
- }
- else
- Total = Total + NumBWritten;
- }
- close(FileDescript);
- }
-
- CloseResFile(refnum);
- }
- }
- }
- }
-
-